package oop.ex1.filters;


import java.io.File;
import java.util.TreeSet;
//###############
//FILE : Filter.java
//WRITER : Amir Wilf, wilfoa, 300007085
//WRITER : Daniel Acherkan, danithelion, 310116348
//EXERCISE : oop ex1 2011
//DESCRIPTION:
//An interface for filtering files
//###############

public abstract class Filter {
	//data members
	
	//_not - Whether this filter has been negated.
	protected boolean _not;
	
	//Constructor
	public Filter(boolean not){
		_not = not;
	}
	
	/**
	 * filter the files according the specific filter class that extends
	 * this abstract class.
	 * @param fullDirectoryFiles A TreeSet of all the files in question, 
	 * before filtering. 
	 * @return A TreeSet of files which matched the filter 
	 */
	public abstract TreeSet<File> filter(TreeSet<File> fullDirectoryFiles);
	
	//This method that inverts the filter selection, 
	//in case the _NOT suffix was applied.
	protected TreeSet<File> addNegation(TreeSet<File> list,
			TreeSet<File> fullDirectoryFiles){
		//if the negation option was applied:
		if(_not){
			TreeSet<File> result = new TreeSet<File>(fullDirectoryFiles);
			result.removeAll(list);
			list = result;
		}
		return list;
	}
}
